﻿using Microsoft.WowAddonStudio.Lua.Loaders;
using Microsoft.WowAddonStudio.Lua.Model;

using NUnit.Framework;

namespace Microsoft.WowAddonStudio.Lua.Tests.Loaders
{
    [TestFixture]
    public class LuaFileDocumentationLoaderTest : FileDocumentationLoaderTestBase<LuaFileDocumentationLoader>
    {
        [Test]
        public void GlobalVariableTest()
        {
            var documentationScope = FileDocumentationLoader.LoadFileDocumentation("../../../Data/FrameXML/GlobalStrings.lua");

            var variable = documentationScope.Resolve<Variable>("ABANDON_PET");

            Assert.IsNotNull(variable);
            Assert.AreEqual(LuaType.String, variable.Type);
        }

        [Test]
        public void GlobalTableTest()
        {
            var documentationScope = FileDocumentationLoader.LoadFileDocumentation("../../../Data/FrameXML/Constants.lua");

            var table = documentationScope.Resolve<Table>("CLASS_SORT_ORDER");

            Assert.IsNotNull(table);
        }

        [Test]
        public void GlobalTableFieldsTest()
        {
            var documentationScope = FileDocumentationLoader.LoadFileDocumentation("../../../Data/FrameXML/Constants.lua");

            var table = documentationScope.Resolve<Table>("CLASS_ICON_TCOORDS");

            Assert.IsNotNull(table);
            Assert.AreEqual(10, table.Declarations.Count);
            Assert.IsNotNull(table.Resolve<Table>("WARRIOR"));
        }

        [Test]
        public void GlobalFunctionTest()
        {
            var documentationScope = FileDocumentationLoader.LoadFileDocumentation("../../../Data/FrameXML/Constants.lua");

            var function = documentationScope.Resolve<Function>("CombatLog_BitToBraceCode");

            Assert.IsNotNull(function);
            Assert.AreEqual(1, function.Parameters.Length);
        }
    }
}
